package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	//_ "newRetailByGolang/automaticExecution"
	"newRetailByGolang/controller"
	"newRetailByGolang/dataInit"
	_ "newRetailByGolang/dataInit"
	"newRetailByGolang/pool"
	"newRetailByGolang/variable"
)

func main() {
	if variable.Db != nil {
		db, _ := variable.Db.DB()
		defer db.Close()
	}

	variable.Sp = pool.NewSimplePoll(5)
	if variable.Sp != nil {
		defer variable.Sp.CloseChan()
	}

	//go func() {
	variable.R = dataInit.NewRedisInit()
	//}()
	if variable.R != nil {
		defer (*variable.R).Close()
	}

	app := fiber.New()
	app.Use(cors.New(cors.Config{
		AllowOrigins:     "*",
		AllowCredentials: true,
		MaxAge:           3600,
		ExposeHeaders:    "*",
		AllowHeaders:     "*",
	}))

	rc := new(controller.RetailController)
	rco := controller.NewRetailController()
	app.Post("/statisticalActivities", rc.StatisticalActivities)
	app.Post("/placeOrder", rco.PlaceOrder)
	app.Post("/placeOrderInPool", rco.PlaceOrderInPool)
	app.Post("/placeOrderInRedisQueue", rco.PlaceOrderInRedisQueue)
	app.Get("/:account/*", rco.NewGetCatalogueInfo)
	app.Listen(":1397")
}
